<link rel="stylesheet" href="<%- Virtual_Path.Static %>jquery.plugin/pagination/pagination.css">
<script src="<%- Virtual_Path.Static %>jquery.plugin/pagination/pagination.js"></script>
<div class="clearfix">
    <div class="x-header-top">
        <div class="header-inner">
            <h2 class="tit">我的粉丝（<em id="J_FansTotal">-</em>）</h2>
        </div>
    </div>
    <div class="main-container">
        <div class="follow-cont">
            <ul class="follow-cont-list clearfix" id="J_FansList">
            </ul>
            <div id="AjaxPagination" class="pagination"></div>
        </div>
    </div>
</div>
<script>
    $(function () {
        if (!_StateData.IsLogin) {
            $.KOC.Tips.Open('Error', '请先登录', {Timeout: 1000});
            location.href = '/';
        }
        var _ThisPage = {
            PageParm: {
                P_Get: true,
                Loading: false, //加载中
                Total: null,       //总条数
                MaxCode: "",    //MaxCode
                Start: 0,       //开始
                Length: 8      //页长度
            }
        };

        $.ajax({
            url: '/ajax/user.user-attention.anchorfans',
            type: 'post',
            dataType: 'json',
            data: {
                P_Get: _ThisPage.PageParm.P_Get,
                P_Total: _ThisPage.PageParm.Total,
                P_MaxCode: _ThisPage.PageParm.MaxCode,
                iDisplayStart: _ThisPage.PageParm.Start,
                iDisplayLength: _ThisPage.PageParm.Length,
                Sort_Col: "Coin",
                Sort_Dir: "DESC"
            },
            success: function (data) {
                _ThisPage.PageParm.Loading = false;
                _ThisPage.PageParm.P_Get = false;
                if (data.flag !== 0) {
                    $.KOC.Tips.Open("Error", data.msg + "(" + data.flag + ")", {Timeout: 3000});
                    return;
                }
                _ThisPage.PageParm.Total = data.iTotalRecords;
                $("#J_FansTotal").text(data.iTotalRecords);
                if (data.iTotalRecords > 0) {
                    $("#AjaxPagination").empty().pagination(data.iTotalRecords, {
                        num_edge_entries: 2, //边缘页数
                        num_display_entries: 5, //主体页数
                        callback: PageCallback,
                        items_per_page: _ThisPage.PageParm.Length, //每页显示1项
                        prev_text: "前一页",
                        next_text: "后一页"
                    });
                } else {
                    var _html = RenderPage(null, data.iTotalRecords);
                    $("#AjaxPagination").empty();
                    $('#J_FansList').empty().html(_html);
                }
            }
        });

        function PageCallback(id) {
            _ThisPage.PageParm.Start = id * _ThisPage.PageParm.Length;
            InitTable(id);
        }

        function InitTable(index) {
            $.ajax({
                url: '/ajax/user.user-attention.anchorfans',
                type: 'post',
                dataType: 'json',
                data: {
                    P_Get: _ThisPage.PageParm.P_Get,
                    P_Total: _ThisPage.PageParm.Total,
                    P_MaxCode: _ThisPage.PageParm.MaxCode,
                    iDisplayStart: _ThisPage.PageParm.Start,
                    iDisplayLength: _ThisPage.PageParm.Length,
                    Sort_Col: "Coin",
                    Sort_Dir: "DESC"
                },
                success: function (data) {
                    _ThisPage.PageParm.Loading = false;
                    _ThisPage.PageParm.P_Get = false;
                    if (data.flag !== 0) {
                        $.KOC.Tips.Open("Error", data.msg + "(" + data.flag + ")", {Timeout: 3000});
                        return;
                    }
                    _ThisPage.PageParm.Total = data.iTotalRecords;
                    _ThisPage.PageParm.MaxCode = data.sMaxCode;
                    _ThisPage.PageParm.Start += _ThisPage.PageParm.Length;
                    $("#J_FansTotal").text(data.iTotalRecords);
                    var _html = '';
                    if (_ThisPage.PageParm.Total > 0) {
                        _.forEach(data.aaData, function (ThisValue) {
                            _html += RenderPage(ThisValue);
                        });
                    }
                    $('#J_FansList').empty().html(_html);
                }
            });
        }

        function RenderPage(ThisValue, len) {
            var _html = '';
            if (len <= 0) {
                _html += '<li>' +
                        '<div class="empty">' + '您还没有粉丝！' +
                        '</div>' +
                        '</li>';
            } else {
                var live = '';
                if (ThisValue.Live > 0) {
                    live = '<i class="ico-live"></i>'
                }
                _html += '<li data-user-id="' + ThisValue.User_ID + '">' +
                        '<div class="info">' +
                        '<img class="user-pic" src=' + $.Common.ImageBind.UserAvatar.fnURL(ThisValue.User_ID, "80.80") + '/>' +
                        live +
                        '<span class="avatar-mask"></span>' +
                        '<p class="nickname"><img src="<%- Virtual_Path.Static %>main/image/common/level/user/' + ThisValue.Level.Level + '.png" alt="' + ThisValue.Level.Level + '" class="ico-lev">' + ThisValue.NickName + '</p>' +
                        '<p class="fans_state">贡献值 '+ThisValue.Coin+'</p>' +
                        '</div>' +
                        '</li>';
            }
            return _html;
        }

    });
</script>